//
//  HJWelcomeController.m
//  newOcWeibo
//
//  Created by heJing on 15/7/27.
//  Copyright (c) 2015年 heima. All rights reserved.
//

#import "HJWelcomeController.h"
#import "HJAccount.h"
#import "UIImageView+WebCache.h"

@interface HJWelcomeController ()

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *iconCons;

@property (weak, nonatomic) IBOutlet UILabel *titleLable;

@property (weak, nonatomic) IBOutlet UIImageView *icon;


@end

@implementation HJWelcomeController

- (void)viewDidLoad {
    [super viewDidLoad];

    HJAccount *account = [HJAccount accountFromSandbox];
    NSURL *url = [NSURL URLWithString:account.profile_image_url];
    self.icon.layer.cornerRadius = 50;
    self.icon.layer.masksToBounds = YES;

    // 下载用户头像
//    [self.icon sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"iOS8"]];

    // 下载用户头像2
    SDWebImageManager *manger = [SDWebImageManager sharedManager];
    [manger downloadImageWithURL:url options:0 progress:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
        
        if (finished) {
            self.icon.image = image;
        }
    }];

}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    [UIView animateWithDuration:1 animations:^{
        // 1.让头像执行动画
        self.iconCons.constant = 150;
        [self.view layoutIfNeeded];
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:1 animations:^{
            // 2.让label执行动画
            self.titleLable.alpha = 1.0;
        } completion:^(BOOL finished) {
            // 3.跳转到首页
            UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            [UIApplication sharedApplication].keyWindow.rootViewController = sb.instantiateInitialViewController;
        }];
    }];

}

@end
